/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "spatial_awareness_mgr_proxy.h"

#include <ipc_types.h>
#include <message_parcel.h>
#include <message_option.h>
#include <string_ex.h>

#include "spatial_awareness_common.h"

namespace OHOS {
namespace Msdp {
float SpatialAwarenessMgrProxy::GetDistance(std::string deviceId)
{
    float distance = 0;
    return distance;
}

float SpatialAwarenessMgrProxy::GetAngle(std::string deviceId)
{
    float angle = 0;
    return angle;
}

uint32_t SpatialAwarenessMgrProxy::GetDirection(std::string deviceId)
{
    uint32_t direction = 0;
    return direction;
}

void SpatialAwarenessMgrProxy::SubscribeSpatialLocationRelationship(const SpatialLocationMode &mode,
    const SpatialDeviceInfo &info, const sptr<ISpatialLocationCallback>& callback)
{
    SPATIAL_LOGI(MODULE_INNERKIT, "SpatialAwarenessMgrProxy:: %{public}s enter", __func__);
    sptr<IRemoteObject> remote = Remote();
    RETURN_IF((remote == nullptr) || (callback == nullptr));

    MessageParcel data;
    MessageParcel reply;
    MessageOption option;

    if (!data.WriteInterfaceToken(SpatialAwarenessMgrProxy::GetDescriptor())) {
        SPATIAL_LOGE(MODULE_INNERKIT, "SpatialAwarenessMgrProxy::%{public}s write descriptor failed!", __func__);
        return;
    }

    WRITE_PARCEL_NO_RET(data, Int32, static_cast<int32_t>(mode));
    WRITE_PARCEL_NO_RET(data, Parcelable, &info);
    WRITE_PARCEL_NO_RET(data, RemoteObject, callback->AsObject());

    int ret = remote->SendRequest(static_cast<int>(ISpatialAwarenessMgr::REG_SPATIAL_LOCATION_CALLBACK),
        data, reply, option);
    if (ret != ERR_OK) {
        SPATIAL_LOGE(MODULE_INNERKIT,
            "SpatialAwarenessMgrProxy::%{public}s SendRequest is failed, error code: %{public}d", __func__, ret);
        return;
    }
}

void SpatialAwarenessMgrProxy::UnSubscribeSpatialLocationRelationship(const SpatialLocationMode &mode,
    const SpatialDeviceInfo &info, const sptr<ISpatialLocationCallback>& callback)
{
    SPATIAL_LOGI(MODULE_INNERKIT, "SpatialAwarenessMgrProxy:: %{public}s enter", __func__);
    sptr<IRemoteObject> remote = Remote();
    RETURN_IF((remote == nullptr) || (callback == nullptr));

    MessageParcel data;
    MessageParcel reply;
    MessageOption option;

    if (!data.WriteInterfaceToken(SpatialAwarenessMgrProxy::GetDescriptor())) {
        SPATIAL_LOGE(MODULE_INNERKIT, "SpatialAwarenessMgrProxy::%{public}s write descriptor failed!", __func__);
        return;
    }
    WRITE_PARCEL_NO_RET(data, Int32, static_cast<int32_t>(mode));
    WRITE_PARCEL_NO_RET(data, Parcelable, &info);
    WRITE_PARCEL_NO_RET(data, RemoteObject, callback->AsObject());

    int ret = remote->SendRequest(static_cast<int>(ISpatialAwarenessMgr::UNREG_SPATIAL_LOCATION_CALLBACK),
        data, reply, option);
    if (ret != ERR_OK) {
        SPATIAL_LOGE(MODULE_INNERKIT,
            "SpatialAwarenessMgrProxy::%{public}s SendRequest is failed, error code: %{public}d", __func__, ret);
        return;
    }
}
} // namespace Msdp
} // namespace OHOS